package com.zhangh.summer.admin.support.ds.redis;


import com.zhangh.summer.admin.support.utils.json.JsonEncoder;
import com.zhangh.summer.admin.support.spring.util.SpringBeanUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import redis.clients.jedis.*;
import redis.clients.util.Pool;
import redis.clients.util.Slowlog;

import java.util.*;

public class RedisClient implements IRedisClient{
	private static final Logger logger = LoggerFactory.getLogger(RedisClient.class);
	private static final Map<String,JedisPool> POOL_MAP=new HashMap<>();
	//private JedisPool pool=null;
	private static final Map<String,JedisSentinelPool> SENTINEL_POOL_MAP=new HashMap<>();
	//private JedisSentinelPool sentinelPool=null;
	private Environment env;
	private boolean isSentinel=false;
	private String redisName;

	/** NX|XX, NX -- Only set the key if it does not already exist. XX -- Only set the key if it already exist. **/
	private static final String NOT_EXIST = "NX";
	private static final String EXIST = "XX";

	/** expx EX|PX, expire time units: EX = seconds; PX = milliseconds **/
	private static final String SECONDS = "EX";
	private static final String MILLISECONDS = "PX";

    public RedisClient(String redisName) {
    	if (null==env){
			env= SpringBeanUtil.getBeanByType(Environment.class);
		}

		this.redisName=redisName;
		String host=env.getProperty("ds.redis."+redisName+".host");
		if (host.contains(",")){//哨兵模式下 host结构 host1:port1,host2:port2,...
			isSentinel=true;
		}
    }

	/**
	 * 获取Jedis
	 * @return
	 */
	public Jedis getResource(){
		if (isSentinel){
			return getJedisSentinelPool().getResource();
		}
		return getJedisPool().getResource();
	}

	public Pool<Jedis> getPool(){
		if (isSentinel){
			return getJedisSentinelPool();
		}
		return getJedisPool();
	}

	/**
	 * 设置值
	 * @param key
	 * @param value
	 * @param seconds 超时时间，0表示不过期
	 * @return
	 */
	public String set(String key,String value,int seconds){
		Jedis jedis = this.getResource();
		try {
			String rt=null;
			if (seconds>0){
				rt=jedis.set(key,value,SECONDS,seconds);
			}else{
				rt=jedis.set(key,value);
			}
			return  rt;
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	/**
	 * 设置值
	 * @param key
	 * @param value 值，可以是java对象，自动转成json存储。
	 * @param seconds 超时时间，0表示不过期
	 * @return
	 */
    public String set(String key,Object value,int seconds){
		Jedis jedis = this.getResource();
		try {
			String rt=null;
			if (seconds>0){
				rt=jedis.set(key, JsonEncoder.DEFAULT.encode(value),SECONDS,seconds);
			}else{
				rt=jedis.set(key,JsonEncoder.DEFAULT.encode(value));
			}
			return rt;
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
    }

	/**
	 * 获取值
	 * @param key
	 * @param clazz 对象class
	 * @param <T>
	 * @return
	 */
    public <T> T get(String key,Class<T> clazz){
		try (Jedis jedis = this.getResource()) {
			String json = jedis.get(key);
			if (StringUtils.isNotEmpty(json)) {
				return JsonEncoder.DEFAULT.decode(json, clazz);
			} else {
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("redis error:{}", e.getMessage());
		}
		return null;
    }

	/**
	 * 获取string值
	 * @param key
	 * @return
	 */
	public String get(String key){
		Jedis jedis = this.getResource();
		try {
			String str=jedis.get(key);
			return str;
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	/**
	 * 获取集合值
	 * @param key
	 * @param collectionClazz 集合class
	 * @param objClazz 集合对象 class
	 * @param <T>
	 * @param <M>
	 * @return
	 */
	public <T,M> T get(String key,Class<T> collectionClazz, Class<M> objClazz){
		Jedis jedis = this.getResource();
		try {
			String json=jedis.get(key);
			if (StringUtils.isNotEmpty(json)){
				return JsonEncoder.DEFAULT.decode(json, collectionClazz,objClazz);
			}else {
				return null;
			}
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;


	}

	@Override
	public String set(String key, String value) {
		Jedis jedis = this.getResource();
		try {
			return jedis.set(key,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String set(String key, String value, String nxxx, String expx, long time) {
		try (Jedis jedis = this.getResource()) {
			return jedis.set(key, value, nxxx, expx, time);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("redis error:{}", e.getMessage());
		}
		return null;
	}

	@Override
	public Boolean exists(String key) {
		try (Jedis jedis = this.getResource()) {
			return jedis.exists(key);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("redis error:{}", e.getMessage());
		}
		return null;
	}

	@Override
	public Long del(String... keys) {
		Jedis jedis = this.getResource();
		try {
			return jedis.del(keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long del(String key) {
		Jedis jedis = this.getResource();
		try {
			return jedis.del(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String type(String key) {
		Jedis jedis = this.getResource();
		try {
			return jedis.type(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<String> keys(String pattern) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.keys(pattern);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String randomKey() {
		Jedis jedis = this.getResource();
		try {
			return  jedis.randomKey();
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String rename(String oldkey, String newkey){
		Jedis jedis = this.getResource();
		try {
			return  jedis.rename(oldkey,newkey);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long renamenx(String oldkey, String newkey) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.renamenx(oldkey,newkey);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long expire(String key, int seconds) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.expire(key,seconds);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long expireAt(String key, long unixTime) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.expireAt(key,unixTime);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long ttl(String key) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.ttl(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long move(String key, int dbIndex) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.move(key,dbIndex);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String getSet(String key, String value){
		Jedis jedis = this.getResource();
		try {
			return  jedis.getSet(key,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> mget(String... keys){
		Jedis jedis = this.getResource();
		try {
			return  jedis.mget(keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long setnx(String key, String value){
		Jedis jedis = this.getResource();
		try {
			return  jedis.setnx(key,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String setex(String key, int seconds, String value) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.setex(key,seconds,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String mset(String... keysvalues) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.mset(keysvalues);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long msetnx(String... keysvalues) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.msetnx(keysvalues);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long decrBy(String key, long integer) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.decrBy(key,integer);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long decr(String key) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.decr(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long incrBy(String key, long integer){
		Jedis jedis = this.getResource();
		try {
			return  jedis.incrBy(key,integer);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Double incrByFloat(String key, double value){
		Jedis jedis = this.getResource();
		try {
			return  jedis.incrByFloat(key,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0.00;
	}

	@Override
	public Long incr(String key){
		Jedis jedis = this.getResource();
		try {
			return  jedis.incr(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long append(String key, String value){
		Jedis jedis = this.getResource();
		try {
			return  jedis.append(key,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String substr(String key, int start, int end){
		Jedis jedis = this.getResource();
		try {
			return  jedis.substr(key,start,end);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long hset(String key, String field, String value){
		Jedis jedis = this.getResource();
		try {
			return  jedis.hset(key,field,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String hget(String key, String field){
		Jedis jedis = this.getResource();
		try {
			return  jedis.hget(key,field);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long hsetnx(String key, String field, String value) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.hsetnx(key,field,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String hmset(String key, Map<String, String> hash){
		Jedis jedis = this.getResource();
		try {
			return  jedis.hmset(key,hash);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String hmset(byte[] key, Map<byte[], byte[]> hash) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.hmset(key,hash);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> hmget(String key, String... fields) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.hmget(key,fields);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long hincrBy(String key, String field, long value){
		Jedis jedis = this.getResource();
		try {
			return  jedis.hincrBy(key,field,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Double hincrByFloat(String key, String field, double value){
		Jedis jedis = this.getResource();
		try {
			return  jedis.hincrByFloat(key,field,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0.00;
	}

	@Override
	public Boolean hexists(String key, String field) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.hexists(key,field);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return false;
	}

	@Override
	public Long hdel(String key, String... fields) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.hdel(key,fields);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long hlen(String key){
		Jedis jedis = this.getResource();
		try {
			return  jedis.hlen(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Set<String> hkeys(String key){
		Jedis jedis = this.getResource();
		try {
			return  jedis.hkeys(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> hvals(String key){
		Jedis jedis = this.getResource();
		try {
			return  jedis.hvals(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Map<String, String> hgetAll(String key){
		Jedis jedis = this.getResource();
		try {
			return  jedis.hgetAll(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Map<byte[], byte[]> hgetAll(byte[] key) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.hgetAll(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long rpush(String key, String... strings){
		Jedis jedis = this.getResource();
		try {
			return  jedis.rpush(key,strings);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long lpush(String key, String... strings){
		Jedis jedis = this.getResource();
		try {
			return  jedis.lpush(key,strings);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long llen(String key) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.llen(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public List<String> lrange(String key, long start, long end){
		Jedis jedis = this.getResource();
		try {
			return  jedis.lrange(key,start,end);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String ltrim(String key, long start, long end){
		Jedis jedis = this.getResource();
		try {
			return  jedis.ltrim(key,start,end);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String lindex(String key, long index){
		Jedis jedis = this.getResource();
		try {
			return  jedis.lindex(key,index);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String lset(String key, long index, String value){
		Jedis jedis = this.getResource();
		try {
			return  jedis.lset(key,index,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long lrem(String key, long count, String value){
		Jedis jedis = this.getResource();
		try {
			return  jedis.lrem(key,count,value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String lpop(String key) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.lpop(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String rpop(String key){
		Jedis jedis = this.getResource();
		try {
			return  jedis.rpop(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String rpoplpush(String srckey, String dstkey) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.rpoplpush(srckey,dstkey);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long sadd(String key, String... members) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.sadd(key,members);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Set<String> smembers(String key) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.smembers(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long srem(String key, String... members){
		Jedis jedis = this.getResource();
		try {
			return  jedis.srem(key,members);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String spop(String key) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.spop(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long smove(String srckey, String dstkey, String member) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.smove(srckey,dstkey,member);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}
	@Override
	public Long scard(String key){
		Jedis jedis = this.getResource();
		try {
			return  jedis.scard(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Boolean sismember(String key, String member) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.sismember(key,member);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return false;
	}

	@Override
	public Set<String> sinter(String... keys) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.sinter(keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long sinterstore(String dstkey, String... keys){
		Jedis jedis = this.getResource();
		try {
			return  jedis.sinterstore(dstkey,keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Set<String> sunion(String... keys){
		Jedis jedis = this.getResource();
		try {
			return  jedis.sunion(keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long sunionstore(String dstkey, String... keys) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.sunionstore(dstkey,keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Set<String> sdiff(String... keys){
		Jedis jedis = this.getResource();
		try {
			return  jedis.sdiff(keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long sdiffstore(String dstkey, String... keys){
		Jedis jedis = this.getResource();
		try {
			return  jedis.sdiffstore(dstkey,keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String srandmember(String key) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.srandmember(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> srandmember(String key, int count) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.srandmember(key,count);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long zadd(String key, double score, String member) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zadd(key,score,member);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long zadd(String key, Map<String, Double> scoreMembers) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zadd(key,scoreMembers);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Set<String> zrange(String key, long start, long end) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrange(key,start,end);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long zrem(String key, String... members) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrem(key,members);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Double zincrby(String key, double score, String member) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zincrby(key,score,member);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0.00;
	}

	@Override
	public Long zrank(String key, String member){
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrank(key,member);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long zrevrank(String key, String member) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrevrank(key,member);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Set<String> zrevrange(String key, long start, long end) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrevrange(key,start,end);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<Tuple> zrangeWithScores(String key, long start, long end){
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrangeWithScores(key,start,end);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<Tuple> zrevrangeWithScores(String key, long start, long end) {
		try (Jedis jedis = this.getResource()) {
			return jedis.zrevrangeWithScores(key, start, end);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("redis error:{}", e.getMessage());
		}
		return null;
	}

	@Override
	public Long zcard(String key) {
		try (Jedis jedis = this.getResource()) {
			return jedis.zcard(key);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("redis error:{}", e.getMessage());
		}
		return 0L;
	}

	@Override
	public Double zscore(String key, String member) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zscore(key,member);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0.00;
	}

	@Override
	public String watch(String... keys){
		Jedis jedis = this.getResource();
		try {
			return  jedis.watch(keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> sort(String key) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.sort(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> sort(String key, SortingParams sortingParameters){
		Jedis jedis = this.getResource();
		try {
			return  jedis.sort(key,sortingParameters);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> blpop(int timeout, String... keys) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.blpop(timeout,keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> blpop(String... args) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.blpop(args);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> brpop(String... args) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.brpop(args);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> blpop(String arg) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.blpop(arg);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> brpop(String arg){
		Jedis jedis = this.getResource();
		try {
			return  jedis.brpop(arg);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long sort(String key, SortingParams sortingParameters, String dstkey) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.sort(key,sortingParameters,dstkey);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long sort(String key, String dstkey) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.sort(key,dstkey);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public List<String> brpop(int timeout, String... keys) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.brpop(timeout,keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long zcount(String key, double min, double max) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zcount(key,min,max);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long zcount(String key, String min, String max){
		Jedis jedis = this.getResource();
		try {
			return  jedis.zcount(key,min,max);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Set<String> zrangeByScore(String key, double min, double max) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrangeByScore(key,min,max);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<String> zrangeByScore(String key, String min, String max) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrangeByScore(key,min,max);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<String> zrangeByScore(String key, double min, double max, int offset, int count) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrangeByScore(key,min,max,offset,count);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<String> zrangeByScore(String key, String min, String max, int offset, int count) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrangeByScore(key,min,max,offset,count);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max){
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrangeByScoreWithScores(key,min,max);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max){
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrangeByScoreWithScores(key,min,max);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrangeByScoreWithScores(key,min,max,offset,count);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max, int offset, int count) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrangeByScoreWithScores(key,min,max,offset,count);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<String> zrevrangeByScore(String key, double max, double min) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrevrangeByScore(key,max,min);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<String> zrevrangeByScore(String key, String max, String min) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrevrangeByScore(key,max,min);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count){
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrevrangeByScore(key,max,min,offset,count);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrevrangeByScoreWithScores(key,max,min);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrevrangeByScoreWithScores(key,max,min,offset,count);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min, int offset, int count){
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<String> zrevrangeByScore(String key, String max, String min, int offset, int count) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrevrangeByScore(key, max, min, offset, count);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zrevrangeByScoreWithScores(key, max, min);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long zremrangeByRank(String key, long start, long end){
		Jedis jedis = this.getResource();
		try {
			return  jedis.zremrangeByRank(key, start, end);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long zremrangeByScore(String key, double start, double end) {
		Jedis jedis = this.getResource();
		try {
			return  jedis.zremrangeByScore(key,start,end);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}
	@Override
	public Long zremrangeByScore(String key, String start, String end) {
		Jedis jedis = this.getResource();
		try {
			return jedis.zremrangeByScore(key, start, end);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long zunionstore(String dstkey, String... sets) {
		try (Jedis jedis = this.getResource()) {
			return jedis.zunionstore(dstkey, sets);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("redis error:{}", e.getMessage());
		}
		return 0L;
	}
	@Override
	public Long zunionstore(String dstkey, ZParams params, String... sets) {
		try (Jedis jedis = this.getResource()) {
			return jedis.zunionstore(dstkey, params, sets);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("redis error:{}", e.getMessage());
		}
		return 0L;
	}

	@Override
	public Long zinterstore(String dstkey, String... sets) {
		Jedis jedis = this.getResource();
		try {
			return jedis.zinterstore(dstkey, sets);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long zinterstore(String dstkey, ZParams params, String... sets) {
		Jedis jedis = this.getResource();
		try {
			return jedis.zinterstore(dstkey, params, sets);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long strlen(String key) {
		Jedis jedis = this.getResource();
		try {
			return jedis.strlen(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long lpushx(String key, String... string) {
		Jedis jedis = this.getResource();
		try {
			return jedis.lpush(key, string);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long persist(String key){
		Jedis jedis = this.getResource();
		try {
			return jedis.persist(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long rpushx(String key, String... string) {
		Jedis jedis = this.getResource();
		try {
			return jedis.rpush(key, string);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String echo(String string) {
		Jedis jedis = this.getResource();
		try {
			return jedis.echo(string);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long linsert(String key, BinaryClient.LIST_POSITION where, String pivot, String value) {
		Jedis jedis = this.getResource();
		try {
			return jedis.linsert(key, where, pivot, value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String brpoplpush(String source, String destination, int timeout){
		Jedis jedis = this.getResource();
		try {
			return jedis.brpoplpush(source, destination, timeout);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Boolean setbit(String key, long offset, boolean value) {
		Jedis jedis = this.getResource();
		try {
			return jedis.setbit(key, offset, value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return false;
	}

	@Override
	public Boolean setbit(String key, long offset, String value) {
		Jedis jedis = this.getResource();
		try {
			return jedis.setbit(key, offset, value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return false;
	}

	@Override
	public Boolean getbit(String key, long offset) {
		Jedis jedis = this.getResource();
		try {
			return jedis.getbit(key, offset);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return false;
	}

	@Override
	public Long setrange(String key, long offset, String value) {
		Jedis jedis = this.getResource();
		try {
			return jedis.setrange(key, offset, value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String getrange(String key, long startOffset, long endOffset) {
		Jedis jedis = this.getResource();
		try {
			return jedis.getrange(key,startOffset,endOffset);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long bitpos(String key, boolean value) {
		Jedis jedis = this.getResource();
		try {
			return jedis.bitpos(key, value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long bitpos(String key, boolean value, BitPosParams params) {
		Jedis jedis = this.getResource();
		try {
			return jedis.bitpos(key, value, params);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public List<String> configGet(String pattern) {
		Jedis jedis = this.getResource();
		try {
			return jedis.configGet(pattern);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String configSet(String parameter, String value) {
		Jedis jedis = this.getResource();
		try {
			return jedis.configSet(parameter, value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Object eval(String script, int keyCount, String... params) {
		Jedis jedis = this.getResource();
		try {
			return jedis.eval(script, keyCount, params);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public void subscribe(JedisPubSub jedisPubSub, String... channels) {
		Jedis jedis = this.getResource();
		try {
			 jedis.subscribe(jedisPubSub, channels);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
	}

	@Override
	public Long publish(String channel, String message) {
		Jedis jedis = this.getResource();
		try {
			return jedis.publish(channel,message);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public void psubscribe(JedisPubSub jedisPubSub, String... patterns) {
		Jedis jedis = this.getResource();
		try {
			 jedis.psubscribe(jedisPubSub, patterns);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
	}

	@Override
	public Object eval(String script, List<String> keys, List<String> args){
		Jedis jedis = this.getResource();
		try {
			return jedis.eval(script, keys, args);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Object eval(String script) {
		Jedis jedis = this.getResource();
		try {
			return jedis.eval(script);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Object evalsha(String script) {
		Jedis jedis = this.getResource();
		try {
			return jedis.evalsha(script);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Object evalsha(String sha1, List<String> keys, List<String> args) {
		Jedis jedis = this.getResource();
		try {
			return jedis.evalsha(sha1, keys, args);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Object evalsha(String sha1, int keyCount, String... params) {
		Jedis jedis = this.getResource();
		try {
			return jedis.evalsha(sha1, keyCount, params);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Boolean scriptExists(String sha1) {
		Jedis jedis = this.getResource();
		try {
			return jedis.scriptExists(sha1);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return false;
	}

	@Override
	public List<Boolean> scriptExists(String... sha1) {
		Jedis jedis = this.getResource();
		try {
			return jedis.scriptExists(sha1);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String scriptLoad(String script) {
		Jedis jedis = this.getResource();
		try {
			return jedis.scriptLoad(script);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<Slowlog> slowlogGet() {
		Jedis jedis = this.getResource();
		try {
			return jedis.slowlogGet();
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<Slowlog> slowlogGet(long entries) {
		Jedis jedis = this.getResource();
		try {
			return jedis.slowlogGet(entries);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}
	@Override
	public Long objectRefcount(String string) {
		Jedis jedis = this.getResource();
		try {
			return jedis.objectRefcount(string);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String objectEncoding(String string) {
		Jedis jedis = this.getResource();
		try {
			return jedis.objectEncoding(string);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long objectIdletime(String string) {
		Jedis jedis = this.getResource();
		try {
			return jedis.objectIdletime(string);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long bitcount(String key) {
		Jedis jedis = this.getResource();
		try {
			return jedis.bitcount(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long bitcount(String key, long start, long end) {
		Jedis jedis = this.getResource();
		try {
			return jedis.bitcount(key, start, end);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long bitop(BitOP op, String destKey, String... srcKeys) {
		Jedis jedis = this.getResource();
		try {
			return jedis.bitop(op, destKey, srcKeys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public List<Map<String, String>> sentinelMasters() {
		Jedis jedis = this.getResource();
		try {
			return jedis.sentinelMasters();
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> sentinelGetMasterAddrByName(String masterName) {
		Jedis jedis = this.getResource();
		try {
			return jedis.sentinelGetMasterAddrByName(masterName);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long sentinelReset(String pattern) {
		Jedis jedis = this.getResource();
		try {
			return jedis.sentinelReset(pattern);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public List<Map<String, String>> sentinelSlaves(String masterName){
		Jedis jedis = this.getResource();
		try {
			return jedis.sentinelSlaves(masterName);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String sentinelFailover(String masterName){
		Jedis jedis = this.getResource();
		try {
			return jedis.sentinelFailover(masterName);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String sentinelMonitor(String masterName, String ip, int port, int quorum) {
		Jedis jedis = this.getResource();
		try {
			return jedis.sentinelMonitor(masterName, ip, port, quorum);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String sentinelRemove(String masterName) {
		Jedis jedis = this.getResource();
		try {
			return jedis.sentinelRemove(masterName);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String sentinelSet(String masterName, Map<String, String> parameterMap) {
		Jedis jedis = this.getResource();
		try {
			return jedis.sentinelSet(masterName, parameterMap);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public byte[] dump(String key) {
		Jedis jedis = this.getResource();
		try {
			return jedis.dump(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String restore(String key, int ttl, byte[] serializedValue){
		Jedis jedis = this.getResource();
		try {
			return jedis.restore(key, ttl, serializedValue);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long pexpire(String key, int milliseconds){
		Jedis jedis = this.getResource();
		try {
			return jedis.pexpire(key,milliseconds);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long pexpire(String key, long milliseconds) {
		Jedis jedis = this.getResource();
		try {
			return jedis.pexpire(key, milliseconds);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long pexpireAt(String key, long millisecondsTimestamp) {
		Jedis jedis = this.getResource();
		try {
			return jedis.pexpireAt(key,millisecondsTimestamp);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Long pttl(String key){
		Jedis jedis = this.getResource();
		try {
			return jedis.pttl(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public String psetex(String key, int milliseconds, String value) {
		Jedis jedis = this.getResource();
		try {
			return jedis.psetex(key, milliseconds, value);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String set(String key, String value, String nxxx) {
		Jedis jedis = this.getResource();
		try {
			return jedis.set(key, value, nxxx);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String set(String key, String value, String nxxx, String expx, int time) {
		Jedis jedis = this.getResource();
		try {
			return jedis.set(key, value, nxxx, expx, time);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}
	@Override
	public String clientKill(String client){
		Jedis jedis = this.getResource();
		try {
			return jedis.clientKill(client);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clientSetname(String name) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clientSetname(name);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String migrate(String host, int port, String key, int destinationDb, int timeout){
		Jedis jedis = this.getResource();
		try {
			return jedis.migrate(host, port, key, destinationDb, timeout);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<String> scan(int cursor) {
		Jedis jedis = this.getResource();
		try {
			return jedis.scan(cursor);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}
	@Override
	public ScanResult<String> scan(int cursor, ScanParams params) {
		Jedis jedis = this.getResource();
		try {
			return jedis.scan(cursor, params);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<Map.Entry<String, String>> hscan(String key, int cursor) {
		Jedis jedis = this.getResource();
		try {
			return jedis.hscan(key, cursor);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<Map.Entry<String, String>> hscan(String key, int cursor, ScanParams params) {
		Jedis jedis = this.getResource();
		try {
			return jedis.hscan(key, cursor, params);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<String> sscan(String key, int cursor) {
		Jedis jedis = this.getResource();
		try {
			return jedis.sscan(key, cursor);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<String> sscan(String key, int cursor, ScanParams params) {
		Jedis jedis = this.getResource();
		try {
			return jedis.sscan(key, cursor, params);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<Tuple> zscan(String key, int cursor) {
		Jedis jedis = this.getResource();
		try {
			return jedis.zscan(key, cursor);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<Tuple> zscan(String key, int cursor, ScanParams params){
		Jedis jedis = this.getResource();
		try {
			return jedis.zscan(key, cursor, params);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}
	@Override
	public ScanResult<String> scan(String cursor) {
		Jedis jedis = this.getResource();
		try {
			return jedis.scan(cursor);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<String> scan(String cursor, ScanParams params) {
		Jedis jedis = this.getResource();
		try {
			return jedis.scan(cursor, params);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}
	@Override
	public ScanResult<Map.Entry<String, String>> hscan(String key, String cursor) {
		Jedis jedis = this.getResource();
		try {
			return jedis.hscan(key,cursor);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<Map.Entry<String, String>> hscan(String key, String cursor, ScanParams params){
		Jedis jedis = this.getResource();
		try {
			return jedis.hscan(key, cursor, params);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}
	@Override
	public ScanResult<String> sscan(String key, String cursor) {
		Jedis jedis = this.getResource();
		try {
			return jedis.sscan(key, cursor);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<String> sscan(String key, String cursor, ScanParams params) {
		Jedis jedis = this.getResource();
		try {
			return jedis.sscan(key, cursor, params);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<Tuple> zscan(String key, String cursor) {
		Jedis jedis = this.getResource();
		try {
			return jedis.zscan(key,cursor);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public ScanResult<Tuple> zscan(String key, String cursor, ScanParams params) {
		Jedis jedis = this.getResource();
		try {
			return jedis.zscan(key, cursor, params);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterNodes() {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterNodes();
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterMeet(String ip, int port) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterMeet(ip,port);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterAddSlots(int... slots) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterAddSlots(slots);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterDelSlots(int... slots) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterDelSlots(slots);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterInfo() {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterInfo();
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> clusterGetKeysInSlot(int slot, int count) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterGetKeysInSlot(slot, count);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterSetSlotNode(int slot, String nodeId) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterSetSlotNode(slot,nodeId);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterSetSlotMigrating(int slot, String nodeId) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterSetSlotMigrating(slot, nodeId);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterSetSlotImporting(int slot, String nodeId) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterSetSlotImporting(slot, nodeId);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterSetSlotStable(int slot) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterSetSlotStable(slot);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterForget(String nodeId) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterForget(nodeId);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterFlushSlots() {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterFlushSlots();
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long clusterKeySlot(String key) {
			Jedis jedis = this.getResource();
			try {
				return jedis.clusterKeySlot(key);
			}catch (Exception e){
				e.printStackTrace();
				logger.error("redis error:{}",e.getMessage());
			}finally {
				jedis.close();
			}
			return null;
		}

	@Override
	public Long clusterCountKeysInSlot(int slot) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterCountKeysInSlot(slot);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterSaveConfig(){
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterSaveConfig();
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterReplicate(String nodeId) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterReplicate(nodeId);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> clusterSlaves(String nodeId) {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterSlaves(nodeId);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String clusterFailover() {
		Jedis jedis = this.getResource();
		try {
			return jedis.clusterFailover();
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public String asking() {
		Jedis jedis = this.getResource();
		try {
			return jedis.asking();
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public List<String> pubsubChannels(String pattern){
		Jedis jedis = this.getResource();
		try {
			return jedis.pubsubChannels(pattern);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	@Override
	public Long pubsubNumPat() {
		Jedis jedis = this.getResource();
		try {
			return jedis.pubsubNumPat();
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public Map<String, String> pubsubNumSub(String... channels){
		Jedis jedis = this.getResource();
		try {
			return jedis.pubsubNumSub(channels);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}



	@Override
	public void setDataSource(Pool<Jedis> jedisPool){
		Jedis jedis = this.getResource();
		try {
			jedis.setDataSource(jedisPool);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
	}

	@Override
	public Long pfadd(String key, String... elements) {
		Jedis jedis = this.getResource();
		try {
			return jedis.pfadd(key,elements);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0L;
	}

	@Override
	public long pfcount(String key){
		Jedis jedis = this.getResource();
		try {
			return jedis.pfcount(key);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0;
	}

	@Override
	public long pfcount(String... keys) {
		Jedis jedis = this.getResource();
		try {
			return jedis.pfcount(keys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return 0;
	}

	@Override
	public String pfmerge(String destkey, String... sourcekeys){
		Jedis jedis = this.getResource();
		try {
			return jedis.pfmerge(destkey, sourcekeys);
		}catch (Exception e){
			e.printStackTrace();
			logger.error("redis error:{}",e.getMessage());
		}finally {
			jedis.close();
		}
		return null;
	}

	//普通模式
	private  JedisPool getJedisPool() {
		//JedisPool pool=POOL_MAP.get(redisName);
		if (POOL_MAP.get(redisName) != null) {
			return POOL_MAP.get(redisName);
		}
		String host=env.getProperty("ds.redis."+redisName+".host");
		int port=Integer.valueOf(env.getProperty("ds.redis."+redisName+".port"));
		String password=env.getProperty("ds.redis."+redisName+".password");
		int timeout=Integer.valueOf(env.getProperty("ds.redis."+redisName+".timeout","2000"));
		int database=Integer.valueOf(env.getProperty("ds.redis."+redisName+".database"));
		int maxActive=Integer.valueOf(env.getProperty("ds.redis."+redisName+".pool.max-active"));
		long maxWait=Long.valueOf(env.getProperty("ds.redis."+redisName+".pool.max-wait"));
		int maxIdle=Integer.valueOf(env.getProperty("ds.redis."+redisName+".pool.max-idle"));
		int minIdle=Integer.valueOf(env.getProperty("ds.redis."+redisName+".pool.min-idle"));

		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxWaitMillis(maxWait);
		config.setMaxIdle(maxIdle);
		config.setMinIdle(minIdle);
		config.setMaxTotal(maxActive);

		config.setTestOnBorrow(false);
		JedisPool pool=null;
		if (StringUtils.isNotEmpty(password)){
			 pool = new JedisPool(config, host,port, timeout,password,database);
		}else {
			 pool = new JedisPool(config, host,port, timeout,(String)null,database);
		}
		POOL_MAP.put(redisName,pool);

		return pool;
	}

	//哨兵模式
	private   JedisSentinelPool  getJedisSentinelPool(){
		//JedisSentinelPool sentinelPool=SENTINEL_POOL_MAP.get(redisName);
		if (null != SENTINEL_POOL_MAP.get(redisName)){
			return  SENTINEL_POOL_MAP.get(redisName);
		}

		String masterName=env.getProperty("ds.redis."+redisName+".master-name");
		String host=env.getProperty("ds.redis."+redisName+".host");
		int port=Integer.valueOf(env.getProperty("ds.redis."+redisName+".port"));
		String password=env.getProperty("ds.redis."+redisName+".password");
		int timeout=Integer.valueOf(env.getProperty("ds.redis."+redisName+".timeout","2000"));
		int database=Integer.valueOf(env.getProperty("ds.redis."+redisName+".database"));
		int maxActive=Integer.valueOf(env.getProperty("ds.redis."+redisName+".pool.max-active"));
		long maxWait=Long.valueOf(env.getProperty("ds.redis."+redisName+".pool.max-wait"));
		int maxIdle=Integer.valueOf(env.getProperty("ds.redis."+redisName+".pool.max-idle"));
		int minIdle=Integer.valueOf(env.getProperty("ds.redis."+redisName+".pool.min-idle"));
		boolean testOnBorrow=Boolean.valueOf(env.getProperty("ds.redis."+redisName+".pool.testOnBorrow","false"));
		boolean testOnReturn=Boolean.valueOf(env.getProperty("ds.redis."+redisName+".pool.testOnReturn","false"));

		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxWaitMillis(maxWait);
		config.setMaxIdle(maxIdle);
		config.setMinIdle(minIdle);
		config.setTestOnBorrow(false);
		config.setMaxTotal(maxActive);
		config.setTestOnBorrow(testOnBorrow);
		config.setTestOnReturn(testOnReturn);

		Set<String> sentinels = new  LinkedHashSet();
		String [] hosts = host.split(",");
		for (int i = 0; i < hosts.length; i++){
			String [] hostArray = hosts[i].split(":");
			sentinels.add(String.format("%s:%s", hostArray[0], hostArray[1]));
		}
		JedisSentinelPool sentinelPool=null;
		if(StringUtils.isNotEmpty(password)){
			sentinelPool= new JedisSentinelPool(masterName, sentinels, config, timeout,password,database);
		}else{
			sentinelPool= new JedisSentinelPool(masterName, sentinels, config, timeout, (String)null,database);
		}
		SENTINEL_POOL_MAP.put(redisName,sentinelPool);
		return  sentinelPool;
	}

}
